package tx.bj12320.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import tx.bj12320.model.*;
import tx.bj12320.dao.*;
import tx.bj12320.service.*;
import tx.bj12320.vo.query.*;

@Service
@Transactional
public class OrgInfoManager extends BaseManager<OrgInfo,Long>{

	private OrgInfoDao orgInfoDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setOrgInfoDao(OrgInfoDao dao) {
		this.orgInfoDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.orgInfoDao;
	}

	@Transactional(readOnly=true)
	public Page findPage(OrgInfoQuery query) {
		return orgInfoDao.findPage(query);
	}

	/**
	 * 得到单位（1级）
	 * @param oi
	 * @return
	 */
	@Transactional(readOnly=true)
	public OrgInfo getLevel1OrgInfo(OrgInfo oi) {
		if(oi.getOrgLevel()==1) {
			return oi;
		}else{
			OrgInfo orgInfo=orgInfoDao.findByProperty("orgInfoId", oi.getParentOrgInfoId());
			return orgInfo;
		}
	}

	/**
	 * 得到部门（2级）
	 * @param oi
	 * @return
	 */
	@Transactional(readOnly=true)
	public List<OrgInfo> findDepartments(Long orgInfoId) {
			return orgInfoDao.findAllBy("parentOrgInfoId", (orgInfoId));
	}
	@Transactional(readOnly=true)
	public List<OrgInfo> findAllLikeByOrgName(String orgName) {
		return orgInfoDao.findAllLikeBy("orgName", "%"+orgName+"%");
	}

	@Transactional(readOnly=true)
	public OrgInfo getByOrgCode(String orgCode) {
		return orgInfoDao.findByProperty("orgCode", orgCode);
	}

}
